namespace pos.entity
{
using System;
using System.Data;
using System.Configuration;
using System.Text;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Criterion;
/// <summary>
/// t_hmoney 的摘要说明
/// </summary>
public class t_hmoney:IEntityUtil
{
	//   列名称哈希表 
	private static Hashtable m_colLabels;    	 
	public static Hashtable colLabels//
	{
		get{return m_colLabels;}
	}
	//表字段名称哈希表
	private static ArrayList m_colNames;     
	public static ArrayList  colNames　
	{
		get{return m_colNames;}
	}
	private Hmoney __hmoney;
	public long seqID  
	{
		get{return __hmoney.seqID;}
		set{ __hmoney.seqID=value;}
	}
	public String userID  
	{
		get{return __hmoney.userID;}
		set{ __hmoney.userID=value;}
	}
	public long cashboxNO  
	{
		get{return __hmoney.cashboxNO;}
		set{ __hmoney.cashboxNO=value;}
	}
	public String saleDate  
	{
		get{return __hmoney.saleDate;}
		set{ __hmoney.saleDate=value;}
	}
	public double sale  
	{
		get{return __hmoney.sale;}
		set{ __hmoney.sale=value;}
	}
	public double cost  
	{
		get{return __hmoney.cost;}
		set{ __hmoney.cost=value;}
	}
	public double profit  
	{
		get{return __hmoney.profit;}
		set{ __hmoney.profit=value;}
	}
	private static  HmoneyDao dao=(HmoneyDao)SpringContext.Context.GetObject("HmoneyDao");
	public static HmoneyDao DAO
	{
		get{return dao;}
		
	}
	
	public t_hmoney()
	{
		__hmoney=new Hmoney();
	  	seqID=consts.long_min;
	  	userID="";
	  	cashboxNO=consts.long_min;
	  	saleDate="";
	  	sale=consts.double_min;
	  	cost=consts.double_min;
	  	profit=consts.double_min;
	  // dao=(HmoneyDao)SpringContext.Context.GetObject("HmoneyDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("seqID", @"销售号");
		colNames.Add("seqID");
		m_colLabels.Add("userID", @"收银员");
		colNames.Add("userID");
		m_colLabels.Add("cashboxNO", @"钱箱");
		colNames.Add("cashboxNO");
		m_colLabels.Add("saleDate", @"销售日期");
		colNames.Add("saleDate");
		m_colLabels.Add("sale", @"销售额");
		colNames.Add("sale");
		m_colLabels.Add("cost", @"进货成本");
		colNames.Add("cost");
		m_colLabels.Add("profit", @"利润");
		colNames.Add("profit");
	  }
	
	}
	public t_hmoney(Hmoney entity )
	{
		__hmoney=entity;
		
	  // dao=(HmoneyDao)SpringContext.Context.GetObject("HmoneyDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("seqID", @"销售号");
		colNames.Add("seqID");
		m_colLabels.Add("userID", @"收银员");
		colNames.Add("userID");
		m_colLabels.Add("cashboxNO", @"钱箱");
		colNames.Add("cashboxNO");
		m_colLabels.Add("saleDate", @"销售日期");
		colNames.Add("saleDate");
		m_colLabels.Add("sale", @"销售额");
		colNames.Add("sale");
		m_colLabels.Add("cost", @"进货成本");
		colNames.Add("cost");
		m_colLabels.Add("profit", @"利润");
		colNames.Add("profit");
	  }
	
	}
	public Object uniqueResult(DetachedCriteria dc)
    {
        return dao.uniqueResult(dc);
    }
	 public DetachedCriteria DC 
     {
        	get{return DetachedCriteria.For(typeof(Hmoney));}
     }
	public const string ENTITYNAME="t_hmoney";
	public const int SEQN0=170;
	
    public void checkAdd()
    {
		int len;
	//try{Convert.ToInt64(seqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	seqID<consts.long_min+1)
			throw (new Exception("请输入销售号"));
 if(				(				  string.Format("{0}",seqID)				  )=="0")
	 throw (new Exception("销售号是主健，框架要求值不能为0"));				

	
	len=userID.Trim().Length;
	if(len>20)
		 throw (new Exception("收银员字符长度最长不能超过20,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("收银员不能为空!"));	
	

	//try{Convert.ToInt64(cashboxNO);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	cashboxNO<consts.long_min+1)
			throw (new Exception("请输入钱箱"));

	
	len=saleDate.Trim().Length;
	if(len>20)
		 throw (new Exception("销售日期字符长度最长不能超过20,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("销售日期不能为空!"));	
	

	//try{Convert.ToDouble(sale);}catch{ throw (new Exception("请输入正确的小数格式"));		}
		if(	sale<consts.double_min+1)
			throw (new Exception("请输入销售额"));
		if(sale>0)
			sale+=0.000001;
		if(sale<0)
			sale-=0.000001;
		
			if(((long)((sale)*100 ))*10!=(long)((sale)*1000) )
				throw (new Exception("销售额小数精度不能大于2位sale="+sale.ToString()));
		if(sale>0)
			sale-=0.000001;
		if(sale<0)
			sale+=0.000001;
	

	//try{Convert.ToDouble(cost);}catch{ throw (new Exception("请输入正确的小数格式"));		}
		if(	cost<consts.double_min+1)
			throw (new Exception("请输入进货成本"));
		if(cost>0)
			cost+=0.000001;
		if(cost<0)
			cost-=0.000001;
		
			if(((long)((cost)*100 ))*10!=(long)((cost)*1000) )
				throw (new Exception("进货成本小数精度不能大于2位cost="+cost.ToString()));
		if(cost>0)
			cost-=0.000001;
		if(cost<0)
			cost+=0.000001;
	

	//try{Convert.ToDouble(profit);}catch{ throw (new Exception("请输入正确的小数格式"));		}
		if(	profit<consts.double_min+1)
			throw (new Exception("请输入利润"));
		if(profit>0)
			profit+=0.000001;
		if(profit<0)
			profit-=0.000001;
		
			if(((long)((profit)*100 ))*10!=(long)((profit)*1000) )
				throw (new Exception("利润小数精度不能大于2位profit="+profit.ToString()));
		if(profit>0)
			profit-=0.000001;
		if(profit<0)
			profit+=0.000001;
	

//unique="yes" 唯一性验证
    }
    public void checkUpdate()
    {
		int len;
	//try{Convert.ToInt64(seqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	seqID<consts.long_min+1)
			throw (new Exception("请输入销售号"));
 if(				(				  string.Format("{0}",seqID)				  )=="0")
	 throw (new Exception("销售号是主健，框架要求值不能为0"));				

	
	len=userID.Trim().Length;
	if(len>20)
		 throw (new Exception("收银员字符长度最长不能超过20,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("收银员不能为空!"));	
	

	//try{Convert.ToInt64(cashboxNO);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	cashboxNO<consts.long_min+1)
			throw (new Exception("请输入钱箱"));

	
	len=saleDate.Trim().Length;
	if(len>20)
		 throw (new Exception("销售日期字符长度最长不能超过20,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("销售日期不能为空!"));	
	

	//try{Convert.ToDouble(sale);}catch{ throw (new Exception("请输入正确的小数格式"));		}
		if(	sale<consts.double_min+1)
			throw (new Exception("请输入销售额"));
		if(sale>0)
			sale+=0.000001;
		if(sale<0)
			sale-=0.000001;
		
			if(((long)((sale)*100 ))*10!=(long)((sale)*1000) )
				throw (new Exception("销售额小数精度不能大于2位sale="+sale.ToString()));
		if(sale>0)
			sale-=0.000001;
		if(sale<0)
			sale+=0.000001;
	

	//try{Convert.ToDouble(cost);}catch{ throw (new Exception("请输入正确的小数格式"));		}
		if(	cost<consts.double_min+1)
			throw (new Exception("请输入进货成本"));
		if(cost>0)
			cost+=0.000001;
		if(cost<0)
			cost-=0.000001;
		
			if(((long)((cost)*100 ))*10!=(long)((cost)*1000) )
				throw (new Exception("进货成本小数精度不能大于2位cost="+cost.ToString()));
		if(cost>0)
			cost-=0.000001;
		if(cost<0)
			cost+=0.000001;
	

	//try{Convert.ToDouble(profit);}catch{ throw (new Exception("请输入正确的小数格式"));		}
		if(	profit<consts.double_min+1)
			throw (new Exception("请输入利润"));
		if(profit>0)
			profit+=0.000001;
		if(profit<0)
			profit-=0.000001;
		
			if(((long)((profit)*100 ))*10!=(long)((profit)*1000) )
				throw (new Exception("利润小数精度不能大于2位profit="+profit.ToString()));
		if(profit>0)
			profit-=0.000001;
		if(profit<0)
			profit+=0.000001;
	

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("seqID", seqID);
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==1)
			return;
		if(list.Count==0)
			throw (new Exception("该记录已经被删除"));	
		else
			throw (new Exception("改纪录出现重名!"));
    }
    public void add()
    {
        try
        {
            checkAdd();
         	dao.Add(__hmoney);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void delByseqID()
    {
    
        try
        {
          dao.Delete(__hmoney);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }

    public  void update()
    {
        try
        {
            checkUpdate();
            dao.Update(__hmoney);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void ExecDataUpdate(int rowNo)
    {
		if(m_updateRow==null)
			return;
		int ii=0;
m_updateRow(rowNo,ii++,				(				  string.Format("{0}",seqID)				  ));	
m_updateRow(rowNo,ii++,userID);	
m_updateRow(rowNo,ii++,				(				  string.Format("{0}",cashboxNO)				  ));	
m_updateRow(rowNo,ii++,saleDate);	
m_updateRow(rowNo,ii++,/***/(						string.Format("{0:F2}",sale)/***/)
);	
m_updateRow(rowNo,ii++,/***/(						string.Format("{0:F2}",cost)/***/)
);	
m_updateRow(rowNo,ii++,/***/(						string.Format("{0:F2}",profit)/***/)
);	

    }
    public void ExecHeadInsert()
    {
		if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,60,"销售号");
			m_insertHead(ii++,60,"收银员");
			m_insertHead(ii++,60,"钱箱");
			m_insertHead(ii++,60,"销售日期");
			m_insertHead(ii++,100,"销售额");
			m_insertHead(ii++,100,"进货成本");
			m_insertHead(ii++,100,"利润");
		}		
    }
    public void ExecDataInsert()
	{
		if(m_insertRow==null)
			return;
		int ii=0;
     	m_insertRow(0,ii++,				(				  string.Format("{0}",seqID)				  ));
     	m_insertRow(0,ii++,userID);
     	m_insertRow(0,ii++,				(				  string.Format("{0}",cashboxNO)				  ));
     	m_insertRow(0,ii++,saleDate);
     	m_insertRow(0,ii++,/***/(						string.Format("{0:F2}",sale)/***/)
);
     	m_insertRow(0,ii++,/***/(						string.Format("{0:F2}",cost)/***/)
);
     	m_insertRow(0,ii++,/***/(						string.Format("{0:F2}",profit)/***/)
);
    }
    public void ExecDataInsertByQuery(DetachedCriteria dc)
    {
      
         IList list=dao.List(dc); 
        
        if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,60,"销售号");
			m_insertHead(ii++,60,"收银员");
			m_insertHead(ii++,60,"钱箱");
			m_insertHead(ii++,60,"销售日期");
			m_insertHead(ii++,100,"销售额");
			m_insertHead(ii++,100,"进货成本");
			m_insertHead(ii++,100,"利润");
		}		
		
      if(m_insertRow!=null)
      {
        int j=0;
        foreach(Hmoney obj in list)			
        {
		  int ii=0;
	     
m_insertRow(j,ii++,				(				  string.Format("{0}",obj.seqID)
				  )
);
m_insertRow(j,ii++,obj.userID.ToString());
m_insertRow(j,ii++,				(				  string.Format("{0}",obj.cashboxNO)
				  )
);
m_insertRow(j,ii++,obj.saleDate.ToString());
m_insertRow(j,ii++,(					string.Format("{0:F2}",obj.sale)
					)
);
m_insertRow(j,ii++,(					string.Format("{0:F2}",obj.cost)
					)
);
m_insertRow(j,ii++,(					string.Format("{0:F2}",obj.profit)
					)
);
		j++;
        }
        

	
       }
    }

    
    public IList List(DetachedCriteria dc)
    {
        try
        {
           
            return dao.List(dc);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
    
    public bool Init(DetachedCriteria dc)
    {
    
    		Hmoney obj=dao.Get(dc);
    		if(obj==null)
    			return false;
    		else
    		{
    			__hmoney=obj;
            	return true;
            }
        
    }
    public static t_hmoney Get(DetachedCriteria dc)
    {
    	
    	Hmoney obj=((HmoneyDao)SpringContext.Context.GetObject("HmoneyDao"))
	 	.Get(dc);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_hmoney( obj );
        
    }
	 public static t_hmoney GetBySeqID(long val)
	 {
	 	Hmoney obj=((HmoneyDao)SpringContext.Context.GetObject("HmoneyDao"))
	 	.GetBySeqID(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_hmoney( obj );
	 	
	 	
	 }
	 public  bool InitBySeqID(long val)
	 {
	 	

	 	Hmoney obj=dao.GetBySeqID(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__hmoney=obj;
	 		return true;
	 	}
	 	
	 	
	 }
    
       public bool showInForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["seqID"]!=null)
		{
			Controls["seqID"].Text=				(				  string.Format("{0}",seqID)				  );
		}
		if(Controls["userID"]!=null)
		{
			Controls["userID"].Text=userID;
		}
		if(Controls["cashboxNO"]!=null)
		{
			Controls["cashboxNO"].Text=				(				  string.Format("{0}",cashboxNO)				  );
		}
		if(Controls["saleDate"]!=null)
		{
			Controls["saleDate"].Text=saleDate;
		}
		if(Controls["sale"]!=null)
		{
			Controls["sale"].Text=/***/(						string.Format("{0:F2}",sale)/***/)
;
		}
		if(Controls["cost"]!=null)
		{
			Controls["cost"].Text=/***/(						string.Format("{0:F2}",cost)/***/)
;
		}
		if(Controls["profit"]!=null)
		{
			Controls["profit"].Text=/***/(						string.Format("{0:F2}",profit)/***/)
;
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    public  t_hmoney Init(Hmoney item)
    {
        __hmoney=item;
        return this;
    }

    
     public bool initByForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["seqID"]!=null)
		{
			
			if(Controls["seqID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["seqID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{seqID=(v==""?consts.long_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["seqID"].Focus();
					throw  (new Exception("销售号格式不正确！！"));
				}
				
			}
			else
			{
				try{seqID=(Controls["seqID"].Text==""?consts.long_min:Convert.ToInt32(Controls["seqID"].Text));}
				catch
				{
					 Controls["seqID"].Focus();
					throw  (new Exception("销售号格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["userID"]!=null)
		{
			
			if(Controls["userID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["userID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{userID=v;}
				catch
				{
					 Controls["userID"].Focus();
					throw  (new Exception("收银员格式不正确！！"));
				}
				
			}
			else
			{
				try{userID=Controls["userID"].Text;}
				catch
				{
					 Controls["userID"].Focus();
					throw  (new Exception("收银员格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["cashboxNO"]!=null)
		{
			
			if(Controls["cashboxNO"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["cashboxNO"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{cashboxNO=(v==""?consts.long_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["cashboxNO"].Focus();
					throw  (new Exception("钱箱格式不正确！！"));
				}
				
			}
			else
			{
				try{cashboxNO=(Controls["cashboxNO"].Text==""?consts.long_min:Convert.ToInt32(Controls["cashboxNO"].Text));}
				catch
				{
					 Controls["cashboxNO"].Focus();
					throw  (new Exception("钱箱格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["saleDate"]!=null)
		{
			
			if(Controls["saleDate"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["saleDate"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{saleDate=v;}
				catch
				{
					 Controls["saleDate"].Focus();
					throw  (new Exception("销售日期格式不正确！！"));
				}
				
			}
			else
			{
				try{saleDate=Controls["saleDate"].Text;}
				catch
				{
					 Controls["saleDate"].Focus();
					throw  (new Exception("销售日期格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["sale"]!=null)
		{
			
			if(Controls["sale"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["sale"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{sale=(v==""?consts.double_min:Convert.ToDouble(v));}
				catch
				{
					 Controls["sale"].Focus();
					throw  (new Exception("销售额格式不正确！！"));
				}
				
			}
			else
			{
				try{sale=(Controls["sale"].Text==""?consts.double_min:Convert.ToDouble(Controls["sale"].Text));}
				catch
				{
					 Controls["sale"].Focus();
					throw  (new Exception("销售额格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["cost"]!=null)
		{
			
			if(Controls["cost"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["cost"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{cost=(v==""?consts.double_min:Convert.ToDouble(v));}
				catch
				{
					 Controls["cost"].Focus();
					throw  (new Exception("进货成本格式不正确！！"));
				}
				
			}
			else
			{
				try{cost=(Controls["cost"].Text==""?consts.double_min:Convert.ToDouble(Controls["cost"].Text));}
				catch
				{
					 Controls["cost"].Focus();
					throw  (new Exception("进货成本格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["profit"]!=null)
		{
			
			if(Controls["profit"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["profit"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{profit=(v==""?consts.double_min:Convert.ToDouble(v));}
				catch
				{
					 Controls["profit"].Focus();
					throw  (new Exception("利润格式不正确！！"));
				}
				
			}
			else
			{
				try{profit=(Controls["profit"].Text==""?consts.double_min:Convert.ToDouble(Controls["profit"].Text));}
				catch
				{
					 Controls["profit"].Focus();
					throw  (new Exception("利润格式不正确！！"));
				}
				
			}
				
				
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    

}

}
